package com.github.aloxc.plugin.restplus.test;


import com.intellij.openapi.progress.ProgressManager;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
/**
 * @author leero
 */
public class HttpClientTestsRunner
{
    public static List<TestResult> runTests(@NotNull List<? extends HttpClientTest> tests) {
        if (tests == null) {
            return null;
        }
        List<TestResult> list = new ArrayList<>(tests.size());
        for (HttpClientTest test : tests) {
            ProgressManager.checkCanceled();
            String name = test.getName();

            long start = System.currentTimeMillis();
            long duration = 0L;
            try {
                test.run();
                list.add(new TestResult(name,true, null));
            }
            catch (Throwable e) {
                list.add(new TestResult(name,false, e.getMessage()));
                duration = System.currentTimeMillis() - start;
            } finally {

            }
        }
        return list;
    }
}